package com.jc.base;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.jc.base.page.Page;
import com.jc.utils.StringUtils;

public class ResultData<T> {
	
	/**
	 * 返回的错误码
	 */
	@JsonProperty("err_code")
	private String errCode;
	
	/**
	 * 返回的错误信息
	 */
	@JsonProperty("err_msg")
	private String errMsg;
	
	/**
	 * 结果的分页信息
	 */
	@JsonInclude(Include.NON_NULL)
	private Page page;
	
	/**
	 * 数据对象
	 */
	@JsonInclude(Include.NON_NULL)
	private T data;

	public String getErrCode() {
		return errCode;
	}

	public void setErrCode(String errCode) {
		this.errCode = errCode;
	}

	public String getErrMsg() {
		String custMsg = ErrMsgManager.getErrMsg(this.errCode);
		if (StringUtils.isNotEmpty(custMsg)) {
			return custMsg;
		}
		return errMsg;
	}

	public void setErrMsg(String errMsg) {
		this.errMsg = errMsg;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}
	
	public void succ(){
		this.errCode ="0";
		this.errMsg ="successe";
	}
	
	@JsonIgnore
	public void fail(ComponentException e){
		this.errCode =e.getErrCode();
		this.errMsg =e.getErrCodeMsg();
	}
	
	@JsonIgnore
	public void fail(String code,String message){
		this.errCode =code;
		this.errMsg =message;
	}
		
}
